package framework.account;

import framework.mvc.FincoContext;

import java.util.Observable;
import java.util.Observer;

public abstract class AAccountObserver<E extends IAccount, T extends IEntry> implements Observer {

    private IAccount account;

    public AAccountObserver(IAccount account) {
        this.account = account;
    }

    @Override
    public void update(Observable o, Object arg) {
        //Update MVC
        FincoContext.getFinco().refresh();

        //Update transaction history
        T entry = (T) arg;
        E acc = (E) o;
        switch (entry.getStatus()) {
            case SUCCESSFUL: {
                successAction(acc, entry);
            }
            break;
            case FAILED: {
                failAction(acc, entry);
            }
            break;
        }
    }

    protected abstract void successAction(IAccount account, IEntry iEntry);

    protected abstract void failAction(IAccount account, IEntry iEntry);


}
